package com.lvandroid.player.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.FrameLayout;

import com.lvandroid.play.player.AllRoundPlayerManager;
import com.lvandroid.play.player.AllRoundPlayer;
import com.lvandroid.play.util.LogUtil;
import com.lvandroid.player.R;

import java.util.ArrayList;
import java.util.List;

public class ImagePlayerActivity extends AppCompatActivity {

    private FrameLayout mContainer;
    private AllRoundPlayer mPlayer;
    private List<String> mUrls = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_player);
        mContainer = findViewById(R.id.container);
        initData();
        initPlay();
    }

    private void initData() {
        Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Video.Media.DATA}
                , null ,null, null);
        int i = 0;
        while(null != c && c.moveToNext()) {
            String path = c.getString(0);
            mUrls.add(path);
            LogUtil.i("wyt", "getImageFile : " + path);
            if(++i == 3) {
                break;
            }
        }
        if(i > 0) {
            c.close();
        }
    }

    private void initPlay() {
        mPlayer = AllRoundPlayerManager.createPlayer(AllRoundPlayerManager.MEDIA_TYPE_IMAGE);
        mPlayer.start(mUrls, mContainer);
    }

}